package com.betting.entity;

import lombok.Data;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import java.time.LocalDateTime;

@Data
@TableName("bet_result")
public class BetResult {
    @TableId(type = IdType.AUTO)
    private Long id;
    private String matchId;
    private LocalDateTime matchTime;
    private String homeTeam;
    private String awayTeam;
    private Double odds;
    private String betType;
    private Double stake;
    private BetResultStatus status;
    private Boolean isWin;
    private Double profit;
    private LocalDateTime createTime;
    private LocalDateTime updateTime;

    public static BetResult valueOf(String value) {
        BetResultStatus status = BetResultStatus.fromValue(value);
        BetResult result = new BetResult();
        result.setStatus(status);
        result.setIsWin(status.isWin());
        return result;
    }

    public void calculateProfit() {
        if (this.status != null && this.stake != null && this.odds != null) {
            double multiplier = this.status.getProfitMultiplier();
            if (multiplier > 0) {
                this.profit = this.stake * (this.odds - 1) * multiplier;
            } else {
                this.profit = this.stake * multiplier;
            }
        }
    }
} 